package org.com.blbl.SubPartitionCount;

import org.apache.hadoop.io.LongWritable;

import org.apache.hadoop.mapreduce.Reducer;
import org.com.blbl.bean.SubPartitionBean;

import java.io.IOException;

public class SubPartitionCountReducer  extends Reducer<SubPartitionBean, LongWritable, SubPartitionBean, LongWritable> {
    LongWritable result = new LongWritable();
    @Override
    protected void reduce(SubPartitionBean key, Iterable<LongWritable> values, Reducer<SubPartitionBean, LongWritable, SubPartitionBean, LongWritable>.Context context) throws IOException, InterruptedException {

        //统计每个分区变量
        long count = 0;
        //遍历一组数组，统计次数，取出该组的所有的Value
        for (LongWritable value : values){
            count += value.get();
            //所有的value进行累加，就是该单词出现的总次数
        }
        result.set(count);
        context.write(key, result);
    }
}
